<template>
  <div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      add-button-text="提交订单"
    />
    <!-- 优惠券单元格 -->
<van-coupon-cell
  :coupons="coupons"
  :chosen-coupon="chosenCoupon"
  @click="showList = true"
/>
 <ul class="m-summary">
  <li class="item">
    <div class="itembox">
      <div>商品合计</div>
      <div>￥1645.00</div>
    </div>
  </li>
  <li class="item">
    <div class="itembox">
      <div>邮费</div>
      <div>￥0.00</div>
    </div>
  </li>
  <li class="item">
    <div class="itembox">
      <div>活动优惠</div>
      <div>-￥0.00</div>
    </div>
  </li>
  <li class="item">
    <div class="itembox">
      <div>优惠券</div>
      <div>-￥0.00</div>
    </div>
  </li>
 </ul>
 <div class="fukuang">应付:1645.00</div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute, type LocationQueryValue } from 'vue-router'
export default defineComponent({
  name: 'ordergoods'
})
</script>
<script lang="ts" setup>
import { ref } from 'vue'
import router from '@/router'
import {getaddress,gettrade} from '@/api/address.'
const trade = ref({})
const detailArrayList = ref([])
const tradeNo = ref('')
        
const route = useRoute()

  const name = route.query.name
  const isDefault = route.query.isDefault
  const tel = route.query.tel
  const address = route.query.address
  const areaCode= route.query.areaCode
  const savefrom = {name,address,tel,isDefault,areaCode}


  
const chosenAddressId = ref<LocationQueryValue|LocationQueryValue[]>(areaCode)
const list = [
  {
    id: savefrom.areaCode,
    name: savefrom.name,
    tel: savefrom.tel,
    address: savefrom.address,
    isDefault: savefrom.isDefault
  }
]

const onAdd = async () => {
  const reslut = await gettrade()
  console.log(reslut)
  trade.value = reslut.data
  console.log(trade.value)
  tradeNo.value = trade.value.tradeNo
  detailArrayList.value = trade.value.detailArrayList
  console.log(detailArrayList.value)
  const params = {
        consignee:"admin1",
        deliveryAddress: "北京市昌平区1",
        paymentWay: 'ONLINE',
        orderComment: "xxxx",
        orderDetailList: detailArrayList.value,
        consigneeTel:'15339259958'
      }
  const res = await getaddress(tradeNo.value,params)
  console.log(res) 
  router.push({
    path: '/pay',
    query:{
      orderId:res.data
    }
  })
}



const coupon = {
      available: 1,
      condition: '无门槛\n最多优惠12元',
      reason: '',
      value: 150,
      name: '优惠券名称',
      startAt: 1489104000,
      endAt: 1514592000,
      valueDesc: '1.5',
      unitDesc: '元',
    };

    const coupons = ref([coupon]);
    const showList = ref(false);
    const chosenCoupon = ref(-1);

</script>

<style lang="less" scoped>
.m-summary{
  width: 375px;
  height: 260px;
  font-size: 14px;
  display: block;
}
.itembox{
  display: flex;
  width: 360px;
  height: 52px;
  margin-left: 8px;
  justify-content: space-between;
}
.item{
  display: block;

  height: 52px;
  line-height: 52px;
  border-bottom: 1px solid #333333;
}
.fukuang{
    position: absolute;
    bottom: 10%;
    color: red;
    font-size: 24px;
    margin-left: 20px;
}
</style>
